using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Web;
using System.Collections;
using System.Web.Services;
using System.Web.Services.Protocols;


[WebService(Namespace = "http://www.microsoft.com/PowerShell")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class CmdletService : System.Web.Services.WebService
{

    public CmdletService()
    {
    }

    /// <summary>
    /// Create a new project
    /// </summary>
    /// <param name="name">The name of the project</param>
    [WebMethod]
    public string NewProject(string name, string description)
    {
        Dictionary<string, object> parameters = new Dictionary<string, object>();
        parameters.Add("@name", name);
        parameters.Add("@description", description);

        // Add the project
        SqlUtils.ExecuteStoredProcedure(Context, "NewProject", parameters);

        return "Project added.";
    }

    /// <summary>
    /// Create a new project user role
    /// </summary>
    /// <param name="name">The name of the project</param>
    [WebMethod]
    public string NewPsSpecUserPermission(string project, string user, string role)
    {
        // Ensure the role is a real role
        Enum.Parse(typeof(PsSpecProjectRole), role, false);

        Dictionary<string, object> parameters = new Dictionary<string, object>();
        parameters.Add("@project", project);
        parameters.Add("@projectUser", user);
        parameters.Add("@role", role);

        // Add the project
        SqlUtils.ExecuteStoredProcedure(Context, "NewProjectUser", parameters);

        return "Project user role added.";
    }

    /// <summary>
    /// Remove a user from a role in a project
    /// </summary>
    /// <param name="name">The name of the project</param>
    [WebMethod]
    public string RemovePsSpecUserPermission(int id)
    {
        Dictionary<string, object> parameters = new Dictionary<string, object>();
        parameters.Add("@id", id);

        // Add the project
        SqlUtils.ExecuteStoredProcedure(Context, "RemoveProjectUser", parameters);

        return "Project user role removed.";
    }

    /// <summary>
    /// Update a project
    /// </summary>
    /// <param name="name">The name of the project</param>
    [WebMethod]
    public string UpdateProject(int id, string name, string description)
    {
        Dictionary<string, object> parameters = new Dictionary<string, object>();
        parameters.Add("@id", id);
        parameters.Add("@name", name);
        parameters.Add("@description", description);

        // Add the project
        SqlUtils.ExecuteStoredProcedure(Context, "UpdateProject", parameters);

        return "Project updated.";
    }

    /// <summary>
    /// Get a project or list of projects
    /// </summary>
    /// <param name="name">The name of the project</param>
    [WebMethod]
    public List<PsSpecProject> GetProject(string name)
    {
        List<PsSpecProject> result = new List<PsSpecProject>();

        Dictionary<string, object> parameters = new Dictionary<string, object>();
        parameters.Add("@name", name);

        // Get the project
        SqlUtils.ExecuteStoredProcedure(Context, "GetProject", parameters, result);

        return result;
    }

    /// <summary>
    /// Create a new project user role
    /// </summary>
    /// <param name="name">The name of the project</param>
    [WebMethod]
    public List<PsSpecUserPermission> GetPsSpecUserPermission(string project, string user, string role)
    {
        if (role != "%")
        {
            // Ensure the role is a real role
            Enum.Parse(typeof(PsSpecProjectRole), role, false);
        }

        List<PsSpecUserPermission> result = new List<PsSpecUserPermission>();

        Dictionary<string, object> parameters = new Dictionary<string, object>();
        parameters.Add("@project", project);
        parameters.Add("@projectUser", user);
        parameters.Add("@role", role);

        // Add the project
        SqlUtils.ExecuteStoredProcedure(Context, "GetProjectUser", parameters, result);

        return result;
    }


    /// <summary>
    /// Remove a new project
    /// </summary>
    /// <param name="name">The name of the project</param>
    [WebMethod]
    public string RemoveProject(int id)
    {
        Dictionary<string, object> parameters = new Dictionary<string, object>();
        parameters.Add("@id", id);

        // Remove the project
        SqlUtils.ExecuteStoredProcedure(Context, "RemoveProject", parameters);

        return "Project removed.";
    }

    /// <summary>
    /// Create a new noun
    /// </summary>
    /// <param name="name">The name of the noun</param>
    /// <param name="definition">The definition of the noun</param>
    [WebMethod]
    public string NewNoun(string name, string description, string project)
    {
        // Add the noun
        Dictionary<string, object> parameters = new Dictionary<string, object>();
        parameters.Add("@name", name);
        parameters.Add("@definition", description);
        parameters.Add("@project", project);

        SqlUtils.ExecuteStoredProcedure(Context, "NewNoun", parameters);

        return "Noun added.";
    }

    /// <summary>
    /// Update a noun
    /// </summary>
    /// <param name="name">The name of the noun</param>
    /// <param name="definition">The current definition of the noun</param>
    /// <param name="newDefinition">The new definition of the noun</param>
    [WebMethod]
    public string UpdateNoun(int id, string name, string definition)
    {
        Dictionary<string, object> parameters = new Dictionary<string, object>();
        parameters.Add("@id", id);
        parameters.Add("@name", name);
        parameters.Add("@definition", definition);

        // Add the project
        SqlUtils.ExecuteStoredProcedure(Context, "UpdateNoun", parameters);

        return "Noun updated.";
    }

    /// <summary>
    /// Remove a noun
    /// </summary>
    /// <param name="name">The name of the noun</param>
    [WebMethod]
    public string RemoveNoun(int id)
    {
        // Remove the noun
        Dictionary<string, object> parameters = new Dictionary<string, object>();
        parameters.Add("@id", id);

        SqlUtils.ExecuteStoredProcedure(Context, "RemoveNoun", parameters);

        return "Noun removed.";
    }

    /// <summary>
    /// Get a noun or list of nouns
    /// </summary>
    /// <param name="name">The name of the noun</param>
    [WebMethod]
    public List<PsSpecNoun> GetNoun(string name, string definition, string project)
    {
        List<PsSpecNoun> result = new List<PsSpecNoun>();

        // Get the noun
        Dictionary<string, object> parameters = new Dictionary<string, object>();
        parameters.Add("@name", name);
        parameters.Add("@definition", definition);
        parameters.Add("@project", project);

        SqlUtils.ExecuteStoredProcedure(Context, "GetNoun", parameters, result);

        return result;
    }

    /// <summary>
    /// Get a verb or list of verbs
    /// </summary>
    /// <param name="name">The name of the verb</param>
    [WebMethod]
    public List<PsSpecVerb> GetVerb(string name)
    {
        List<PsSpecVerb> result = new List<PsSpecVerb>();

        // Get the verb

        Dictionary<string, object> parameters = new Dictionary<string, object>();
        parameters.Add("@name", name);

        SqlUtils.ExecuteStoredProcedure(Context, "GetVerb", parameters, result);

        return result;
    }

    /// <summary>
    /// Create a new cmdlet
    /// </summary>
    /// <param name="snapin">The name of the snapin</param>
    /// <param name="verb">The verb for this cmdlet</param>
    /// <param name="noun">The noun for this cmdlet</param>
    /// <param name="project">The project for this cmdlet</param>
    [WebMethod]
    public string NewCmdlet(string snapin, string verb, string noun, string projectName,
            string teamMembers, string shortDescription, string helpShortDescription, string longDescription,
            string helpLongDescription, string status, string helpStatus, bool supportsShouldProcess,
            string notes, string specExamples, PsSpecHelpExample[] helpExamples, string inputObject,
            string helpInputObjectDescription,
            string outputObject, string outputObjectDescription, string helpOutputObjectDescription,
            string defaultParameterSetName, string relatedTo, string custom1, string custom2,
            string custom3, string custom4, string helpAdditionalNotes)
    {
        // Add the cmdlet
        Dictionary<string, object> parameters = new Dictionary<string, object>();
        parameters.Add("@snapin", snapin);
        parameters.Add("@verb", verb);
        parameters.Add("@noun", noun);
        parameters.Add("@project", projectName);
        parameters.Add("@teamMembers", teamMembers);
        parameters.Add("@shortDescription", shortDescription);
        parameters.Add("@longDescription", longDescription);
        parameters.Add("@supportsShouldProcess", supportsShouldProcess);
        parameters.Add("@notes", notes);
        parameters.Add("@specExamples", specExamples);
        parameters.Add("@outputObject", outputObject);
        parameters.Add("@outputObjectDescription", outputObjectDescription);
        parameters.Add("@relatedTo", relatedTo);
        parameters.Add("@defaultParameterSetName", defaultParameterSetName);
        parameters.Add("@custom1", custom1);
        parameters.Add("@custom2", custom2);
        parameters.Add("@custom3", custom3);
        parameters.Add("@custom4", custom4);
        parameters.Add("@status", status);
        parameters.Add("@helpStatus", helpStatus);
        parameters.Add("@helpShortDescription", helpShortDescription);
        parameters.Add("@helpLongDescription", helpLongDescription);
        parameters.Add("@inputObject", inputObject);
        parameters.Add("@helpInputObjectDescription", helpInputObjectDescription);
        parameters.Add("@helpOutputObjectDescription", helpOutputObjectDescription);
        parameters.Add("@helpAdditionalNotes", helpAdditionalNotes);

        SqlUtils.ExecuteStoredProcedure(Context, "NewCmdlet", parameters);

        // Get the cmdlet, and update its help examples
        if (helpExamples != null)
        {
            List<PsSpecCmdlet> cmdlets = GetCmdlet(verb + "-" + noun, projectName);
            PsSpecCmdlet newCmdlet = cmdlets[0];

            foreach (PsSpecHelpExample currentExample in helpExamples)
            {
                parameters = new Dictionary<string, object>();
                parameters.Add("@cmdletId", newCmdlet.Id);
                parameters.Add("@command", currentExample.Command);
                parameters.Add("@output", currentExample.Output);
                parameters.Add("@description", currentExample.Description);

                SqlUtils.ExecuteStoredProcedure(Context, "AddHelpExample", parameters);
            }
        }

        return "Cmdlet added.";
    }

    /// <summary>
    /// Update a new cmdlet
    /// </summary>
    [WebMethod]
    public string UpdateCmdlet(int id, string snapin, string verb, string noun,
        string teamMembers, string shortDescription, string helpShortDescription, string longDescription,
        string helpLongDescription, string status, string helpStatus, bool? supportsShouldProcess,
        string notes, string specExamples, PsSpecHelpExample[] helpExamples, string inputObject,
        string helpInputObjectDescription, string outputObject, string outputObjectDescription,
        string helpOutputObjectDescription, string defaultParameterSetName, string relatedTo, string custom1,
        string custom2, string custom3, string custom4, string helpAdditionalNotes, String ProjectName)
    {
        // Update the cmdlet
        Dictionary<string, object> parameters = new Dictionary<string, object>();

        parameters.Add("@cmdletId", id);
        parameters.Add("@snapin", snapin);
        parameters.Add("@verb", verb);
        parameters.Add("@noun", noun);
        parameters.Add("@teamMembers", teamMembers);
        parameters.Add("@shortDescription", shortDescription);
        parameters.Add("@longDescription", longDescription);
        parameters.Add("@supportsShouldProcess", supportsShouldProcess);
        parameters.Add("@notes", notes);
        parameters.Add("@specExamples", specExamples);
        parameters.Add("@outputObject", outputObject);
        parameters.Add("@outputObjectDescription", outputObjectDescription);
        parameters.Add("@relatedTo", relatedTo);
        parameters.Add("@defaultParameterSetName", defaultParameterSetName);
        parameters.Add("@custom1", custom1);
        parameters.Add("@custom2", custom2);
        parameters.Add("@custom3", custom3);
        parameters.Add("@custom4", custom4);
        parameters.Add("@status", status);
        parameters.Add("@helpStatus", helpStatus);
        parameters.Add("@helpShortDescription", helpShortDescription);
        parameters.Add("@helpLongDescription", helpLongDescription);
        parameters.Add("@inputObject", inputObject);
        parameters.Add("@helpInputObjectDescription", helpInputObjectDescription);
        parameters.Add("@helpOutputObjectDescription", helpOutputObjectDescription);
        parameters.Add("@helpAdditionalNotes", helpAdditionalNotes);

        SqlUtils.ExecuteStoredProcedure(Context, "UpdateCmdlet", parameters);

        // Now update the help examples
        List<PsSpecHelpExample> existingHelpExamples = GetPsSpecHelpExample(verb + "-" + noun, ProjectName);
        List<PsSpecHelpExample> needToAddExamples = new List<PsSpecHelpExample>();
        List<PsSpecHelpExample> needToUpdateExamples = new List<PsSpecHelpExample>();
        List<PsSpecHelpExample> needToDeleteExamples = new List<PsSpecHelpExample>();


        // Find the examples that we need to add or change
        foreach (PsSpecHelpExample incomingHelpExample in helpExamples)
        {
            if (existingHelpExamples.Contains(incomingHelpExample))
            {
                // Do the update, if necessary
                PsSpecHelpExample existingHelpExample =
                    existingHelpExamples[existingHelpExamples.IndexOf(incomingHelpExample)];

                if (((existingHelpExample.Command != incomingHelpExample.Command) ||
                    (existingHelpExample.Output != incomingHelpExample.Output) ||
                    (existingHelpExample.Description != incomingHelpExample.Description)) &&
                    (existingHelpExample.Id == incomingHelpExample.Id))
                {
                    parameters = new Dictionary<string, object>();
                    parameters.Add("@helpExampleId", incomingHelpExample.Id);
                    parameters.Add("@command", incomingHelpExample.Command);
                    parameters.Add("@output", incomingHelpExample.Output);
                    parameters.Add("@description", incomingHelpExample.Description);

                    SqlUtils.ExecuteStoredProcedure(Context, "UpdateHelpExample", parameters);
                }

                // Remove this from the list of items we need to examine
                existingHelpExamples.Remove(incomingHelpExample);
            }
            else
            {
                // Add the example
                parameters = new Dictionary<string, object>();
                parameters.Add("@cmdletId", id);
                parameters.Add("@command", incomingHelpExample.Command);
                parameters.Add("@output", incomingHelpExample.Output);
                parameters.Add("@description", incomingHelpExample.Description);

                SqlUtils.ExecuteStoredProcedure(Context, "AddHelpExample", parameters);
            }
        }

        // Anything remaining in existingHelpExamples needs to be deleted
        foreach (PsSpecHelpExample existingHelpExample in existingHelpExamples)
        {
            // Delete the example
            parameters = new Dictionary<string, object>();
            parameters.Add("@id", existingHelpExample.Id);

            SqlUtils.ExecuteStoredProcedure(Context, "RemoveHelpExample", parameters);
        }

        return "Cmdlet updated.";
    }


    /// <summary>
    /// Get a cmdlet or list of cmdlets
    /// </summary>
    /// <param name="name">The name of the cmdlet</param>
    [WebMethod]
    public List<PsSpecCmdlet> GetCmdlet(string name, string project)
    {
        List<PsSpecCmdlet> result = new List<PsSpecCmdlet>();

        // Get the cmdlet
        Dictionary<string, object> parameters = new Dictionary<string, object>();
        parameters.Add("@name", name);
        parameters.Add("@project", project);

        SqlUtils.ExecuteStoredProcedure(Context, "GetCmdlet", parameters, result);

        return result;
    }

    /// <summary>
    /// Remove a cmdlet
    /// </summary>
    /// <param name="name">The name of the cmdlet</param>
    [WebMethod]
    public string RemoveCmdlet(int id)
    {
        // Remove the cmdlet
        Dictionary<string, object> parameters = new Dictionary<string, object>();
        parameters.Add("@id", id);

        SqlUtils.ExecuteStoredProcedure(Context, "RemoveCmdlet", parameters);

        return "Cmdlet removed.";
    }

    /// <summary>
    /// Create a new cmdlet parameter
    /// </summary>
    /// <param name="cmdletName">The name of the cmdlet</param>
    /// <param name="parameterName">The name of this parametercmdlet</param>
    [WebMethod]
    public string NewPsSpecCmdletParameter(string projectName, string cmdletName, string parameterName, string type,
        string description, string aliases,
        bool? allowGlobbing,
        bool? allowMultiple, bool? isDynamic, bool? allowEmptyCollection, bool? allowEmptyString,
        bool? allowNull, string validateCount, bool? validateNotNull, bool? validateNotNullOrEmpty,
        string validateRange, string validateSet, string validateLength, string validatePattern,
        string notes, string defaultValue, string custom1, string custom2, string custom3,
        string custom4, string helpDescription)
    {
        // Add the cmdlet
        Dictionary<string, object> parameters = new Dictionary<string, object>();

        parameters.Add("@projectName", projectName);
        parameters.Add("@cmdletName", cmdletName);
        parameters.Add("@parameterName", parameterName);
        parameters.Add("@type", type);
        parameters.Add("@description", description);
        parameters.Add("@aliases", aliases);
        parameters.Add("@allowGlobbing", allowGlobbing);
        parameters.Add("@allowMultiple", allowMultiple);
        parameters.Add("@allowEmptyCollection", allowEmptyCollection);
        parameters.Add("@allowEmptyString", allowEmptyString);
        parameters.Add("@allowNull", allowNull);
        parameters.Add("@validateCount", validateCount);
        parameters.Add("@validateNotNull", validateNotNull);
        parameters.Add("@validateNotNullOrEmpty", validateNotNullOrEmpty);
        parameters.Add("@validateRange", validateRange);
        parameters.Add("@validateSet", validateSet);
        parameters.Add("@validateLength", validateLength);
        parameters.Add("@validatePattern", validatePattern);
        parameters.Add("@notes", notes);
        parameters.Add("@isDynamic", isDynamic);
        parameters.Add("@defaultValue", defaultValue);
        parameters.Add("@custom1", custom1);
        parameters.Add("@custom2", custom2);
        parameters.Add("@custom3", custom3);
        parameters.Add("@custom4", custom4);
        parameters.Add("@helpDescription", helpDescription);

        SqlUtils.ExecuteStoredProcedure(Context, "NewParameter", parameters);

        return "Parameter added.";
    }

    /// <summary>
    /// Get a cmdlet or list of cmdlets
    /// </summary>
    /// <param name="name">The name of the cmdlet</param>
    [WebMethod]
    public List<PsSpecCmdletParameter> GetPsSpecCmdletParameter(string name, string type, string description,
        string cmdletName, string projectName)
    {
        List<PsSpecCmdletParameter> result = new List<PsSpecCmdletParameter>();

        // Get the cmdlet
        Dictionary<string, object> parameters = new Dictionary<string, object>();
        parameters.Add("@name", name);
        parameters.Add("@type", type);
        parameters.Add("@description", description);
        parameters.Add("@cmdlet", cmdletName);
        parameters.Add("@project", projectName);

        SqlUtils.ExecuteStoredProcedure(Context, "GetParameter", parameters, result);

        return result;
    }


    /// <summary>
    /// Remove a cmdlet parameter
    /// </summary>
    /// <param name="cmdletName">The name of the cmdlet</param>
    /// <param name="parameterName">The name of the parameter</param>
    [WebMethod]
    public string RemovePsSpecCmdletParameter(int id)
    {
        // Remove the cmdlet
        Dictionary<string, object> parameters = new Dictionary<string, object>();
        parameters.Add("@id", id);

        SqlUtils.ExecuteStoredProcedure(Context, "RemoveParameter", parameters);

        return "Parameter removed.";
    }

    /// <summary>
    /// Update a cmdlet parameter
    /// </summary>
    /// <param name="cmdletName">The name of the cmdlet</param>
    /// <param name="parameterName">The name of this parametercmdlet</param>
    [WebMethod]
    public string UpdatePsSpecCmdletParameter(
        int id, string parameterName, string type,
        string description, string aliases,
        bool? allowGlobbing,
        bool? allowMultiple, bool? isDynamic, bool? allowEmptyCollection, bool? allowEmptyString,
        bool? allowNull, string validateCount, bool? validateNotNull, bool? validateNotNullOrEmpty,
        string validateRange, string validateSet, string validateLength, string validatePattern,
        string notes, string defaultValue, string custom1, string custom2, string custom3,
        string custom4, string helpDescription)
    {
        // Add the cmdlet
        Dictionary<string, object> parameters = new Dictionary<string, object>();

        parameters.Add("@id", id);
        parameters.Add("@parameterName", parameterName);
        parameters.Add("@type", type);
        parameters.Add("@description", description);
        parameters.Add("@aliases", aliases);
        parameters.Add("@allowGlobbing", allowGlobbing);
        parameters.Add("@allowMultiple", allowMultiple);
        parameters.Add("@allowEmptyCollection", allowEmptyCollection);
        parameters.Add("@allowEmptyString", allowEmptyString);
        parameters.Add("@allowNull", allowNull);
        parameters.Add("@validateCount", validateCount);
        parameters.Add("@validateNotNull", validateNotNull);
        parameters.Add("@validateNotNullOrEmpty", validateNotNullOrEmpty);
        parameters.Add("@validateRange", validateRange);
        parameters.Add("@validateSet", validateSet);
        parameters.Add("@validateLength", validateLength);
        parameters.Add("@validatePattern", validatePattern);
        parameters.Add("@notes", notes);
        parameters.Add("@isDynamic", isDynamic);
        parameters.Add("@defaultValue", defaultValue);
        parameters.Add("@custom1", custom1);
        parameters.Add("@custom2", custom2);
        parameters.Add("@custom3", custom3);
        parameters.Add("@custom4", custom4);
        parameters.Add("@helpDescription", helpDescription);

        SqlUtils.ExecuteStoredProcedure(Context, "UpdateParameter", parameters);

        return "Parameter updated.";
    }

    /// <summary>
    /// Create a new cmdlet parameter set
    /// </summary>
    /// <param name="cmdletName">The name of the cmdlet</param>
    /// <param name="parameterName">The name of this parametercmdlet</param>
    [WebMethod]
    public string NewParameterSetEntry(string projectName, string cmdletName, string parameterSetName,
        string parameterName, bool mandatory, int? position, bool valueFromPipeline,
        bool valueFromPipelineByPropertyName, bool valueFromRemainingArguments, string helpMessage,
        string helpMessageBaseName, string helpMessageResourceId)
    {
        // Add the cmdlet
        Dictionary<string, object> parameters = new Dictionary<string, object>();

        parameters.Add("@projectName", projectName);
        parameters.Add("@cmdletName", cmdletName);
        parameters.Add("@parameterSetName", parameterSetName);
        parameters.Add("@parameterName", parameterName);
        parameters.Add("@mandatory", mandatory);
        parameters.Add("@position", position);
        parameters.Add("@valueFromPipeline", valueFromPipeline);
        parameters.Add("@valueFromPipelineByPropertyName", valueFromPipelineByPropertyName);
        parameters.Add("@valueFromRemainingArguments", valueFromRemainingArguments);
        parameters.Add("@helpMessage", helpMessage);
        parameters.Add("@helpMessageBaseName", helpMessageBaseName);
        parameters.Add("@helpMessageResourceId", helpMessageResourceId);

        SqlUtils.ExecuteStoredProcedure(Context, "NewParameterSetEntry", parameters);

        return "Parameter set entry added.";
    }

    /// <summary>
    /// Get a cmdlet or list of parameters
    /// </summary>
    /// <param name="name">The name of the cmdlet</param>
    [WebMethod]
    public List<PsSpecCmdletParameterSetEntry> GetPsSpecCmdletParameterSetEntry(string projectName, string cmdletName, string parameterName, string parameterSetName)
    {
        List<PsSpecCmdletParameterSetEntry> result = new List<PsSpecCmdletParameterSetEntry>();

        // Get the cmdlet
        Dictionary<string, object> parameters = new Dictionary<string, object>();
        parameters.Add("@parameterSetName", parameterSetName);
        parameters.Add("@parameterName", parameterName);
        parameters.Add("@cmdlet", cmdletName);
        parameters.Add("@project", projectName);

        SqlUtils.ExecuteStoredProcedure(Context, "GetParameterSetEntry", parameters, result);

        return result;
    }


    /// <summary>
    /// Remove a cmdlet parameter set entry
    /// </summary>
    /// <param name="cmdletName">The name of the cmdlet</param>
    /// <param name="parameterName">The name of the parameter</param>
    [WebMethod]
    public string RemovePsSpecCmdletParameterSetEntry(int id)
    {
        // Remove the cmdlet
        Dictionary<string, object> parameters = new Dictionary<string, object>();
        parameters.Add("@id", id);

        SqlUtils.ExecuteStoredProcedure(Context, "RemoveParameterSetEntry", parameters);

        return "Parameter set entry removed.";
    }

    /// <summary>
    /// Update a cmdlet parameter set entry
    /// </summary>
    /// <param name="cmdletName">The name of the cmdlet</param>
    /// <param name="parameterName">The name of this parametercmdlet</param>
    [WebMethod]
    public string UpdatePsSpecCmdletParameterSetEntry(
        int id,
        bool? mandatory, int? position, string parameterSetName, bool? valueFromPipeline, bool? valueFromPipelineByPropertyName,
        bool? valueFromRemainingArguments, string helpMessage, string helpMessageBaseName, string helpMessageResourceId)
    {
        // Add the cmdlet
        Dictionary<string, object> parameters = new Dictionary<string, object>();

        parameters.Add("@parameterSetEntryId", id);
        parameters.Add("@parameterSetName", parameterSetName);
        parameters.Add("@mandatory", mandatory);
        parameters.Add("@position", position);
        parameters.Add("@valueFromPipeline", valueFromPipeline);
        parameters.Add("@valueFromPipelineByPropertyName", valueFromPipelineByPropertyName);
        parameters.Add("@valueFromRemainingArguments", valueFromRemainingArguments);
        parameters.Add("@helpMessage", helpMessage);
        parameters.Add("@helpMessageBaseName", helpMessageBaseName);
        parameters.Add("@helpMessageResourceId", helpMessageResourceId);

        SqlUtils.ExecuteStoredProcedure(Context, "UpdateParameterSetEntry", parameters);

        return "Parameter set entry updated.";
    }

    /// <summary>
    /// Get the top parameters for a project
    /// </summary>
    [WebMethod]
    public List<PsSpecCmdletParameterGroupEntry> GetTopParameters(string projectName)
    {
        // Add the project name
        Dictionary<string, object> parameters = new Dictionary<string, object>();
        parameters.Add("@project", projectName);

        List<PsSpecCmdletParameterGroupEntry> result = new List<PsSpecCmdletParameterGroupEntry>();
        SqlUtils.ExecuteStoredProcedure(Context, "GetTopParameters", parameters, result);

        return result;
    }

    /// <summary>
    /// Get the spec history
    /// </summary>
    [WebMethod]
    public List<PsSpecHistoryEntry> GetPsSpecHistory(int id, string changeType, DateTime from, DateTime to)
    {
        // Ensure the change type is a real change type
        Enum.Parse(typeof(PsSpecHistoryChangeType), changeType, false);
        if (from == DateTime.MinValue)
        {
            from = DateTime.Parse("1/1/1753 12:00:00 AM",
                new System.Globalization.CultureInfo("en-US").DateTimeFormat);
        }
        if (to == DateTime.MaxValue)
        {
            to = DateTime.Parse("12/31/9999 11:59:59 PM",
                new System.Globalization.CultureInfo("en-US").DateTimeFormat);
        }


        // Add the parameters
        Dictionary<string, object> parameters = new Dictionary<string, object>();
        parameters.Add("@id", id);
        parameters.Add("@changeType", changeType);
        parameters.Add("@from", from);
        parameters.Add("@to", to);

        List<PsSpecHistoryEntry> result = new List<PsSpecHistoryEntry>();
        SqlUtils.ExecuteStoredProcedure(Context, "GetSpecHistory", parameters, result);

        return result;
    }


    /// <summary>
    /// Get help examples
    /// </summary>
    [WebMethod]
    public List<PsSpecHelpExample> GetPsSpecHelpExample(String CmdletName, String ProjectName)
    {
        // Add the parameters
        Dictionary<string, object> parameters = new Dictionary<string, object>();
        parameters.Add("@cmdletName", CmdletName);
        parameters.Add("@project", ProjectName);

        List<PsSpecHelpExample> result = new List<PsSpecHelpExample>();
        SqlUtils.ExecuteStoredProcedure(Context, "GetHelpExample", parameters, result);

        return result;
    }

}

